<?php
    header("content-type:text/html; charset=utf8");
    $con = mysqli_connect("localhost", "root", "guodong", "study");
    mysqli_set_charset($con, "utf8");

    class Stus
    {
        public $id;
        public $name;
        public $age;
        public $sex;
        public $class;
    }

    if ($con) {
        $select_list = "SELECT * FROM stu";
        $result = mysqli_query($con, $select_list);

        foreach ($result as $row) {
            $stus = new Stus();
            $stus->id = $row["id"];
            $stus->name = $row["name"];
            $stus->age = $row["age"];
            $stus->sex = $row["sex"];
            $stus->class = $row["class"];
            $data[] = $stus;
        }
        echo json_encode($data);
    } else {
        echo "数据库连接失败！";
    }
